﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Business.WPF;
using Presenters.WPF.Views;

namespace Presenters.WPF
{
    public class SearchInscriptionPresenter
    {
        public ISearchInscriptionView View;

        public SearchInscriptionPresenter(ISearchInscriptionView view)
        {
            this.View = view;
        }
        public void SearchInscription()
        {
            if (this.View.isSearchBySubjectSigla)
                SearchInscriptionBySubjectSigla();
            if (this.View.isSearchBySubjectCode)
                SearchInscriptionBySubjectCOD();
            if (this.View.isSearchBySubjectName)
                SearchInscriptionBySubjectNam();
        }

        private void SearchInscriptionBySubjectNam()
        {
            try 
            {
                SearchInscriptionManager sim = new SearchInscriptionManager();
                this.View.inscriptionResults = sim.SearchInscriptionBySubjectname(this.View.searchTextBox);
            }
            catch (Exception ex)
            {
                this.View.message = "Error " + ex.Message;
            }
        }

        private void SearchInscriptionBySubjectCOD()
        {
            try
            {
                SearchInscriptionManager sim = new SearchInscriptionManager();
                this.View.inscriptionResults = sim.SearchInscriptionBySubjectCode(Convert.ToInt64(this.View.searchTextBox));
            }
            catch (Exception ex)
            {
                this.View.message = "Error " + ex.Message;
            }
        }
        public void SearchInscriptionBySubjectSigla()
        {
            try
            {
                SearchInscriptionManager sim = new SearchInscriptionManager();
                this.View.inscriptionResults = sim.SearchInscriptionBySubjectSigla(this.View.searchTextBox);
            }
            catch (Exception ex)
            {
                this.View.message = "Error " + ex.Message;
            }
        }
    }
}
